
$(document).ready(function(){
	$("#add").hide();
	$('table a').click(function(){
		var action = $(this).attr('id');
		var userId = $(this).attr('name');
		window.parent.right.location.href="../RMS/main/user/"+action+"?userId="+userId;
	});
	
	$('span a').click(function(){
		$("#add").show(1000);
		disactive();
		$('#userManager').hide(1000);
	});
	$('#cancel').click(function(){
		$("#add").hide(1000);
		$('#userManager').show(1000);
	});
	
});
var b1 = false;
var b2 = false;
var b3 = false;
function validateU(name){
	disactive();//将按钮设置成不可用
	var patt1 = /[a-z]/;
	var patt2 = /[A-Z]/;
	var patrn=/^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){4,19}$/; 
	if(name==""){
		alert("用户名不能为空！请输入用户名！");
		b1 = false;
	}else if(name.length<5||name.length>20){
		alert("用户名长度错误！请输入正确数位的用户名！");
		document.getElementById("userName").value = "";
		b1 = false;
	}else if((/[a-z]/.test(name.substr(0,1))||/[A-Z]/.test(name.substr(0,1)))==false){
		alert("用户名必须为字母开头");
		document.getElementById("userName").value = "";
		b1 = false;
	}else if(!patrn.exec(name)){
		alert("用户名必须为字母、数字或下划线的组合！");
		document.getElementById("userName").value = "";
		b1 = false;
	}else{
		b1 = true;
		active();
	}
}
function validateP(password){//验证密码
	disactive();//将按钮设置成不可用
	if(password.length<5||password==""){
		alert("密码长度必须大于5！请输入正确密码长度！");
		b2 = false;
	}else{
		b2 = true;
		active()
	}
}

function validateC(confrimPassword){//验证确认密码是否和原密码相等
	disactive();
	var password = document.getElementById("password").value;
	if(confrimPassword!=password||confrimPassword==""){
		alert("确认密码有误！请输入正确密码！");
		document.getElementById("confrimPassword").value = '';
		b3 = false;
	}else{
		b3 = true;
		active();
	}
}

function validateD(userDesc){//验证确认密码是否和原密码相等
	if(userDesc.length>255){
		alert("用户描述过长，请填写小于255字符！");
		disactive();
	}else{
		active();
	}
}

function active(){//激活按钮
	if(b1&&b2&&b3){
		$(document).ready(function(){
			$("#submit").removeAttr("disabled");
		});
	}
}

function disactive(){//按钮禁用
	$(document).ready(function(){
		$("#submit").attr("disabled","true");
	});
}


